package ycl.security.handler;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Service;
import ycl.common.ApiResult;
import ycl.common.utils.ServletUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 退出登录成功
 *
 * @author ycl
 * @date 2022-03-10 13:08:54
 */
@Service("authLogoutSuccessHandler")
public class AuthLogoutSuccessHandler implements LogoutSuccessHandler {
	@Override
	public void onLogoutSuccess(
			HttpServletRequest request,
			HttpServletResponse response,
			Authentication authentication) throws IOException, ServletException {
		ServletUtil.setResultResponse(response);
		ApiResult<Object> result = ApiResult.success();
		response.getWriter().write(JSONObject.toJSONString(result));
	}
}
